package com.zg.sign.util;


import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.zg.sign.vo.UploadUnsignedFilesVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Component
@Slf4j
@RefreshScope
public class CaSignUtil {

    @Value("${sign.requestUrl}")
    private  String url ;


    /**
     * 上传未签章文件
     * @param file
     * @return
     * @throws IOException
     */
    public UploadUnsignedFilesVo uploadUnsignedFile(MultipartFile file) throws IOException {
        String resultStr = HttpUtil
                .createPost(url +"/v2/api/serCebSign/uploadBatchFile")
                .contentType("application/json;charset=UTF-8")
                .body(file.getBytes())
                .execute().body();
        log.info("请求地址："+url);
        log.info("响应结果："+resultStr);
        return JSON.toJavaObject(JSON.parseObject(resultStr), UploadUnsignedFilesVo.class);
    }
}
